<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>emp-toolkit: /Users/wangxiao/git/emp-toolkit/emp-tool/circuits/batcher.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo-full-doxygen.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">emp-toolkit
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('batcher_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">batcher.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="batcher_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef BATCHER_H__</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define BATCHER_H__</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="backend_8h.html">backend.h</a>&quot;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="keyword">using</span> std::vector;</div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;</div><div class="line"><a name="l00007"></a><span class="lineno"><a class="line" href="class_batcher.html">    7</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_batcher.html">Batcher</a> { <span class="keyword">public</span>:</div><div class="line"><a name="l00008"></a><span class="lineno"><a class="line" href="class_batcher.html#a2684d2fa879918696dae586b305f12c1">    8</a></span>&#160;    vector&lt;bool&gt; <a class="code" href="class_batcher.html#a2684d2fa879918696dae586b305f12c1">values</a>;</div><div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="class_batcher.html#ac175e627566a37e2b63579c4dac57012">    9</a></span>&#160;    vector&lt;int&gt; <a class="code" href="class_batcher.html#ac175e627566a37e2b63579c4dac57012">lens</a>;</div><div class="line"><a name="l00010"></a><span class="lineno"><a class="line" href="class_batcher.html#aaf86010ac38e95ce3619d7092e25cb1f">   10</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_batcher.html#aaf86010ac38e95ce3619d7092e25cb1f">len_ptr</a> = 0;</div><div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="class_batcher.html#a969c9caa6f6dabe9c64cd78620bfc4af">   11</a></span>&#160;    <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * <a class="code" href="class_batcher.html#a969c9caa6f6dabe9c64cd78620bfc4af">labels</a> = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00012"></a><span class="lineno"><a class="line" href="class_batcher.html#a22a8b07302ed0ca50baf7c16d6e3a1ce">   12</a></span>&#160;    <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * <a class="code" href="class_batcher.html#a22a8b07302ed0ca50baf7c16d6e3a1ce">label_ptr</a> = <span class="keyword">nullptr</span>;</div><div class="line"><a name="l00013"></a><span class="lineno"><a class="line" href="class_batcher.html#a1f732dd655ca0992866771f5ad11e089">   13</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_batcher.html#a1f732dd655ca0992866771f5ad11e089">add</a>(<span class="keywordtype">bool</span> * b, <span class="keywordtype">int</span> length) {</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;        lens.push_back(length);</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; length; ++i)</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;            values.push_back(b[i]);</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    }</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;</div><div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="class_batcher.html#abc184208ebc9d8360f6d50bc927d86ae">   19</a></span>&#160;    <a class="code" href="class_batcher.html#abc184208ebc9d8360f6d50bc927d86ae">~Batcher</a>(){</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        <span class="keywordflow">if</span>(labels != <span class="keyword">nullptr</span>)</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;            <span class="keyword">delete</span>[] <a class="code" href="class_batcher.html#a969c9caa6f6dabe9c64cd78620bfc4af">labels</a>;</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    }</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T, <span class="keyword">typename</span>... Args&gt;</div><div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="class_batcher.html#a89e2783a4b2191b4d1baf6b02c2223e0">   25</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_batcher.html#a89e2783a4b2191b4d1baf6b02c2223e0">add</a>(Args&amp;&amp;... args) {</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        <span class="keywordtype">int</span> length = T::bool_size(std::forward&lt;Args&gt;(args)...);</div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="keywordtype">bool</span> * tmp = <span class="keyword">new</span> <span class="keywordtype">bool</span>[length];</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;        T::bool_data(tmp, std::forward&lt;Args&gt;(args)...);</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        <a class="code" href="class_batcher.html#a1f732dd655ca0992866771f5ad11e089">add</a>(tmp, length);</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;        <span class="keyword">delete</span> []tmp;</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    }</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="class_batcher.html#aad72b5dd1862fb8fc0355d3bc98ad8f2">   33</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_batcher.html#aad72b5dd1862fb8fc0355d3bc98ad8f2">to_bool</a>(<span class="keywordtype">bool</span> * b) {</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i = 0; i &lt; values.size(); ++i){</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;            b[i] = values[i];</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;        }</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    }</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    </div><div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="class_batcher.html#aee252ae214e29ccb150420c0cc1c452a">   39</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_batcher.html#aee252ae214e29ccb150420c0cc1c452a">make_semi_honest</a>(<span class="keywordtype">int</span> <a class="code" href="input-check-malicious_8cpp.html#aefdd5aa9f02e7cb8d21ea22b0e6b03df">party</a>, <a class="code" href="class_backend.html">Backend</a> * be = <span class="keyword">nullptr</span>) {</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        <span class="keywordflow">if</span>(be == <span class="keyword">nullptr</span>)</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;            be = <a class="code" href="backend_8cpp.html#ad9476de428d45c84de795f4157a9dc10">local_backend</a>;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <span class="keywordtype">bool</span> * bools = <span class="keyword">new</span> <span class="keywordtype">bool</span>[<a class="code" href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">size</a>()];</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <a class="code" href="class_batcher.html#aad72b5dd1862fb8fc0355d3bc98ad8f2">to_bool</a>(bools);</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        label_ptr = labels = <span class="keyword">new</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>[<a class="code" href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">size</a>()];</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        <a class="code" href="backend_8cpp.html#ad9476de428d45c84de795f4157a9dc10">local_backend</a>-&gt;<a class="code" href="class_backend.html#a99c19c1e1b66bd835145fddcade401c9">Feed</a>(labels, party, bools, <a class="code" href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">size</a>());</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        len_ptr = 0;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <span class="keyword">delete</span>[] bools;</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    }</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="class_batcher.html#a141f3d52e241d5a0cbcef2a4c5c576ad">   50</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_batcher.html#a141f3d52e241d5a0cbcef2a4c5c576ad">set_blocks</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * b) {</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;        this-&gt;labels = b;</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        this-&gt;label_ptr = b;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        len_ptr = 0;</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    }</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div><div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="class_batcher.html#a67b1da75db465dfee2e91ae8abd23686">   57</a></span>&#160;    T <a class="code" href="class_batcher.html#a67b1da75db465dfee2e91ae8abd23686">next</a>() {</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        T res = T(lens[len_ptr], label_ptr);</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        label_ptr +=lens[<a class="code" href="class_batcher.html#aaf86010ac38e95ce3619d7092e25cb1f">len_ptr</a>];</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        len_ptr ++;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        <span class="keywordflow">return</span> res;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno"><a class="line" href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">   64</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">size</a>() {</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        <span class="keywordflow">return</span> values.size();</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    }</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;};</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="class_batcher_html_aee252ae214e29ccb150420c0cc1c452a"><div class="ttname"><a href="class_batcher.html#aee252ae214e29ccb150420c0cc1c452a">Batcher::make_semi_honest</a></div><div class="ttdeci">void make_semi_honest(int party, Backend *be=nullptr)</div><div class="ttdef"><b>Definition:</b> batcher.h:39</div></div>
<div class="ttc" id="class_batcher_html_a89e2783a4b2191b4d1baf6b02c2223e0"><div class="ttname"><a href="class_batcher.html#a89e2783a4b2191b4d1baf6b02c2223e0">Batcher::add</a></div><div class="ttdeci">void add(Args &amp;&amp;... args)</div><div class="ttdef"><b>Definition:</b> batcher.h:25</div></div>
<div class="ttc" id="garble_2block_8h_html_a65abbf31b0a30290189cdb5059b5f785"><div class="ttname"><a href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a></div><div class="ttdeci">__m128i block</div><div class="ttdef"><b>Definition:</b> block.h:8</div></div>
<div class="ttc" id="class_batcher_html_abc184208ebc9d8360f6d50bc927d86ae"><div class="ttname"><a href="class_batcher.html#abc184208ebc9d8360f6d50bc927d86ae">Batcher::~Batcher</a></div><div class="ttdeci">~Batcher()</div><div class="ttdef"><b>Definition:</b> batcher.h:19</div></div>
<div class="ttc" id="class_batcher_html_a1f732dd655ca0992866771f5ad11e089"><div class="ttname"><a href="class_batcher.html#a1f732dd655ca0992866771f5ad11e089">Batcher::add</a></div><div class="ttdeci">void add(bool *b, int length)</div><div class="ttdef"><b>Definition:</b> batcher.h:13</div></div>
<div class="ttc" id="class_batcher_html_a22a8b07302ed0ca50baf7c16d6e3a1ce"><div class="ttname"><a href="class_batcher.html#a22a8b07302ed0ca50baf7c16d6e3a1ce">Batcher::label_ptr</a></div><div class="ttdeci">block * label_ptr</div><div class="ttdef"><b>Definition:</b> batcher.h:12</div></div>
<div class="ttc" id="class_batcher_html_aad72b5dd1862fb8fc0355d3bc98ad8f2"><div class="ttname"><a href="class_batcher.html#aad72b5dd1862fb8fc0355d3bc98ad8f2">Batcher::to_bool</a></div><div class="ttdeci">void to_bool(bool *b)</div><div class="ttdef"><b>Definition:</b> batcher.h:33</div></div>
<div class="ttc" id="class_batcher_html_a2684d2fa879918696dae586b305f12c1"><div class="ttname"><a href="class_batcher.html#a2684d2fa879918696dae586b305f12c1">Batcher::values</a></div><div class="ttdeci">vector&lt; bool &gt; values</div><div class="ttdef"><b>Definition:</b> batcher.h:8</div></div>
<div class="ttc" id="class_batcher_html_a969c9caa6f6dabe9c64cd78620bfc4af"><div class="ttname"><a href="class_batcher.html#a969c9caa6f6dabe9c64cd78620bfc4af">Batcher::labels</a></div><div class="ttdeci">block * labels</div><div class="ttdef"><b>Definition:</b> batcher.h:11</div></div>
<div class="ttc" id="class_backend_html_a99c19c1e1b66bd835145fddcade401c9"><div class="ttname"><a href="class_backend.html#a99c19c1e1b66bd835145fddcade401c9">Backend::Feed</a></div><div class="ttdeci">void Feed(block *lbls, int party, const bool *b, int nel)</div><div class="ttdef"><b>Definition:</b> backend.h:12</div></div>
<div class="ttc" id="class_batcher_html_a141f3d52e241d5a0cbcef2a4c5c576ad"><div class="ttname"><a href="class_batcher.html#a141f3d52e241d5a0cbcef2a4c5c576ad">Batcher::set_blocks</a></div><div class="ttdeci">void set_blocks(block *b)</div><div class="ttdef"><b>Definition:</b> batcher.h:50</div></div>
<div class="ttc" id="class_batcher_html_a67b1da75db465dfee2e91ae8abd23686"><div class="ttname"><a href="class_batcher.html#a67b1da75db465dfee2e91ae8abd23686">Batcher::next</a></div><div class="ttdeci">T next()</div><div class="ttdef"><b>Definition:</b> batcher.h:57</div></div>
<div class="ttc" id="class_batcher_html_ac175e627566a37e2b63579c4dac57012"><div class="ttname"><a href="class_batcher.html#ac175e627566a37e2b63579c4dac57012">Batcher::lens</a></div><div class="ttdeci">vector&lt; int &gt; lens</div><div class="ttdef"><b>Definition:</b> batcher.h:9</div></div>
<div class="ttc" id="class_batcher_html_aaf86010ac38e95ce3619d7092e25cb1f"><div class="ttname"><a href="class_batcher.html#aaf86010ac38e95ce3619d7092e25cb1f">Batcher::len_ptr</a></div><div class="ttdeci">int len_ptr</div><div class="ttdef"><b>Definition:</b> batcher.h:10</div></div>
<div class="ttc" id="class_backend_html"><div class="ttname"><a href="class_backend.html">Backend</a></div><div class="ttdef"><b>Definition:</b> backend.h:8</div></div>
<div class="ttc" id="backend_8cpp_html_ad9476de428d45c84de795f4157a9dc10"><div class="ttname"><a href="backend_8cpp.html#ad9476de428d45c84de795f4157a9dc10">local_backend</a></div><div class="ttdeci">Backend * local_backend</div><div class="ttdef"><b>Definition:</b> backend.cpp:7</div></div>
<div class="ttc" id="class_batcher_html"><div class="ttname"><a href="class_batcher.html">Batcher</a></div><div class="ttdef"><b>Definition:</b> batcher.h:7</div></div>
<div class="ttc" id="input-check-malicious_8cpp_html_aefdd5aa9f02e7cb8d21ea22b0e6b03df"><div class="ttname"><a href="input-check-malicious_8cpp.html#aefdd5aa9f02e7cb8d21ea22b0e6b03df">party</a></div><div class="ttdeci">int party</div><div class="ttdef"><b>Definition:</b> input-check-malicious.cpp:12</div></div>
<div class="ttc" id="backend_8h_html"><div class="ttname"><a href="backend_8h.html">backend.h</a></div></div>
<div class="ttc" id="class_batcher_html_a37992ea15a1a81fea1763a357a12472d"><div class="ttname"><a href="class_batcher.html#a37992ea15a1a81fea1763a357a12472d">Batcher::size</a></div><div class="ttdeci">int size()</div><div class="ttdef"><b>Definition:</b> batcher.h:64</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_eec959d81771dc8b1a750b834e1341eb.html">emp-tool</a></li><li class="navelem"><a class="el" href="dir_2b4671b717884caf3b3fe5ce6896c1bb.html">circuits</a></li><li class="navelem"><a class="el" href="batcher_8h.html">batcher.h</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.12 </li>
  </ul>
</div>
</body>
</html>
